package com.awei.study.design.structure.facade;

/**
 * @Author liweilong
 * @Date 2024/8/8 13:32
 * 外观模式
 */
public class Facade {

    public static class Tv {
        public void on() {
            System.out.println("电视开了");
        }
        public void off() {
            System.out.println("电视关了");
        }
    }

    public static class Light {
        public void on() {
            System.out.println("灯开了");
        }
        public void off() {
            System.out.println("灯关了");
        }
    }

    public static class AirCondition {
        public void on() {
            System.out.println("空调开了");
        }
        public void off() {
            System.out.println("空调关了");
        }
    }

    public static class SmartAide {
        private Tv tv;
        private Light light;
        private AirCondition ac;

        public SmartAide() {
            tv = new Tv();
            light = new Light();
            ac = new AirCondition();
        }

        public void on() {
            System.out.println("起床了");
            tv.on();
            light.on();
            ac.off();
        }
        public void off() {
            System.out.println("睡觉了");
            tv.off();
            light.off();
            ac.on();
        }

        public void order(String msg) {
            if(msg.contains("打开")) {
                on();
            }else if(msg.contains("关闭")) {
                off();
            }else {
                System.out.println("不清楚您的指令");
            }
        }


    }

    public static void main(String[] args) {
        SmartAide sa = new SmartAide();
        sa.order("打开电器");
        sa.order("关闭电器");
    }
}
